﻿function Remove-TSMFileSpace {
    <#
        .SYNOPSIS
            Remove TSM filespace
                    
        .DESCRIPTION
            The Remove-TSMFileSpace removes a TSM filespace
        
        .EXAMPLE
            Remove-TSMFileSpace nodeA *

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/03/2015
    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0, Mandatory = $true)]
        $Node,
        
        [Parameter(Position = 1, Mandatory = $true)]
        $FileSpaceName,
        
        [ValidateSet("Server","Unicode","FSID")]
        $FileSpaceNameType,

        [ValidateSet("Any","Backup","Archive","SpaceManaged","Server")]
        $Type = "Any",

        [switch]$Async
    )

    $command = "Delete Filespace $Node $FileSpaceName Type=$Type"

    if (($FileSpaceNameType -ne $null) -and ($FileSpaceNameType -ne "")) {
        $command += " NameType=$FileSpaceNameType"
    }
    
    if ($Async) {
        $command += " Wait=Yes"
    } 

    $output = Invoke-TSMCommand -Command $command

    return $output
}